<?php
function wl_log($str)
{
//	if(define('ENV_DEBUG'))
//	{
		error_log($str);
//	}
}

function wl_file_log($type,$log)
{
	$type_arr = array(
		'alipay_sys_error' => 'alipay_sys_error.txt',
		'alipay_log' => 'alipay_log.txt',
	);

	if(!isset($type_arr[$type]))
	{
		return;
	}

	$filename = $type_arr[$type];
	$log .= "\n";

	$log_file = "/opt/wwwroot/wl/channels/static.wealink.com/logs/".$filename;

	$fp = fopen($log_file,"a+");
	flock($fp, LOCK_EX);

	fwrite($fp,$log);
	flock($fp, LOCK_UN);
	fclose($fp);
}

function wl_fix_length_str($str,$len=16)
{
	$count = mb_strwidth($str,'utf-8');
	if($len - $count > 0)
	{
		for($i=0;$i<$len - $count;$i++)
		{
			$str .= " ";
		}
	}
	return $str;
}

function wl_array_to_logstr($arr)
{
	if(!is_array($arr))
	{
		return;
	}

	$str = '';

	foreach($arr as $k=>$v)
	{
		$str .= wl_fix_length_str($k)."= ";
		$str .= $v."\n";
	}
	return $str;
}

